package com.c8a.validation.utils;

import com.c8a.validation.entity.GroupEmployee;
import org.hibernate.validator.spi.group.DefaultGroupSequenceProvider;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @Author C8A
 * @Date 2022-04-24 18:40
 * @Email 1912327276@qq.com
 */

public class EmployeeGroupSequenceProvider implements DefaultGroupSequenceProvider<GroupEmployee> {
    /**
     * 举例
     * 1、员工的 age 在 20-25 之间，title 必须以 "初级" 开头
     * 2、员工的 age 在 25-30 之间，title 必须以 "中级" 开头
     * 3、否则，不做验证
     */
    @Override
    public List<Class<?>> getValidationGroups(GroupEmployee groupEmployee) {

        List<Class<?>> defaultGroupSequence = new ArrayList<>();
        defaultGroupSequence.add(GroupEmployee.class);

        if (!Objects.isNull(groupEmployee)) {
            if (20 < groupEmployee.getAge() && groupEmployee.getAge() <= 25) {
                defaultGroupSequence.add(GroupEmployee.TitleJunior.class);
            } else if (25 < groupEmployee.getAge() && groupEmployee.getAge() <= 30) {
                defaultGroupSequence.add(GroupEmployee.TitleMiddle.class);
            }
        }
        return defaultGroupSequence;
    }
}
